﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ADEVSO.Net;
using System.Configuration;
using System.IO;

namespace SmartParking.Web
{
    public partial class JoinBusiness : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            (Master as Template).Title = "Afíliese a SmartParking";
        }

        protected void ddlRefer_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlRefer.SelectedItem.Value == "O")
                lbDetalle.Visible = tboxOther.Visible = true;
            else
                lbDetalle.Visible = tboxOther.Visible = false;
        }

        protected void ddlPosition_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlPosition.SelectedItem.Value == "O")
                lbDetailPos.Visible = tboxOtherPos.Visible = true;
            else
                lbDetailPos.Visible = tboxOtherPos.Visible = false;
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            Mail oContact = new Mail();
            oContact.From = ConfigurationManager.AppSettings["smtpUser"];
            oContact.To = ConfigurationManager.AppSettings["salesMail"];
            oContact.Subject = "Solicitud de Registro de Parqueo";

            StreamReader srTemplate = File.OpenText(Server.MapPath("~/media/doc/mailContact.htm"));
            string sBody = srTemplate.ReadToEnd();
            srTemplate.Close();

            sBody = sBody.Replace("{mail}", tboxEmail.Text);
            sBody = sBody.Replace("{name}", tboxName.Text);
            sBody = sBody.Replace("{lastname}", tboxLastName.Text);
            sBody = sBody.Replace("{parking}", tboxParking.Text);
            sBody = sBody.Replace("{address}", tboxAddress.Text);
            sBody = sBody.Replace("{phone}", tboxPhone.Text);
            sBody = sBody.Replace("{quantity}", tboxQuantity.Text);

            if (ddlPosition.SelectedValue == "O")
                sBody = sBody.Replace("{position}", tboxOtherPos.Text);
            else
                sBody = sBody.Replace("{position}", ddlPosition.SelectedItem.Text);

            if (ddlRefer.SelectedValue == "O")
                sBody = sBody.Replace("{refer}", tboxOther.Text);
            else
                sBody = sBody.Replace("{refer}", ddlRefer.SelectedItem.Text);

            sBody = sBody.Replace("{optional}", tboxOptional.Text);

            oContact.Body = sBody;
            oContact.SmtpServer = ConfigurationManager.AppSettings["smtpServer"];
            oContact.Port = 25;
            oContact.User = ConfigurationManager.AppSettings["smtpUser"];
            oContact.Password = ConfigurationManager.AppSettings["smtpPassword"];

            oContact.Send();
        }
    }
}
